/*
 * @(#)Computer.java
 *
 */

package diablo3.process;

import java.util.Calendar;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import diablo3.support.Util;

/**
 * description
 * @author  huangyixiang
 * @version 2012-12-20
 */
public class Computer {
	
	private static final Log LOG = LogFactory.getLog(Computer.class);
	Processer processer = new Processer();

	public String setSystemPowerOffTime(float hour){
		if(hour <= 0){
			LOG.info("设置的关机时间不正确（setSystemPowerOffTime error）  hour : " + hour);
			return null;
		}
		String order = "shutdown -s -t ";
		int seconds = (int)(hour * 3600);
		order += seconds;
		processer.exec(order, true);
		
		Calendar c = Calendar.getInstance();
		c.add(Calendar.SECOND , seconds);
		LOG.info("" + hour + "小时 = " + seconds + "秒 后关机");
		String powerOffTime = Util.formatDate2String(c.getTime());
		LOG.info("关机时间为: " + powerOffTime);
		return powerOffTime;
	}
	
	public void restart(){
		processer.startProcess("shutdown -r");
	}
}
